<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/fmt.tld" prefix="fmt" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
	<div class="Wrapper">
		<div>
			<form id="ligerForm" action="">
				<div class="fieldset1 tabel_col clearFix">
					<div class="caption">
						<span class="title">移交详情&权证资料</span>						
					</div>
		<!--  是否需要解押材料 start  -->
		<c:if test="${sign=='006'}">	
				<div class="fieldBox col_100">
					<div class="label"><font color="red">*</font>是否需要解押材料</div>
					<div class="field">
		                    <input name="isNeed" onclick="isShowInfor(1)" type="radio" value="1"  disabled <c:if test='${avo.isNeed==1 }'> checked </c:if> >是
		                    <input name="isNeed" onclick="isShowInfor(0)" type="radio" value="0" disabled <c:if test='${avo.isNeed==0 }'> checked </c:if> >否
					</div>
				</div>
				<div id="jieYaInfo" style="display: none;" >
					<div class="fieldBox col_50">
						<div class="label"><font color="red">*</font>解押材料申请表</div>
						<div class="field">
								<jsp:include page="/WEB-INF/views/system/sysUlFilesRec/sysUlFilesRecUploadW.jsp" flush="true" >
									<jsp:param name="filePath" value="arcfile/transfer"/>
									 <jsp:param name="fileNum" value="1"/>
								</jsp:include>
								 	<input id="tabNm"  name="tabNm"  type="hidden"  value="ARC_TRANSFER_MAIN">
					</div>
					</div>
					<!-- 附件显示 -->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="ligergrid_file1" class="sq-grid"></div>
						</div>
					</div>
					<%-- <div class="fieldBox col_50">
						<div class="label"><a target="_blank" href="${jie_up_file_path}">下载解押材料申请表</a></div>
					</div> --%>
				</div>
			</c:if>
			<!--  是否需要解押材料 end -->	
		<!-- 签收单及解押资料回执上传 签收单 003 -->	
			<c:if test="${sign=='003'}">	
				<div class="fieldBox col_50">
						<div class="label"><font color="red">*</font>签收单</div>
						<div class="field">
								<jsp:include page="/WEB-INF/views/system/sysUlFilesRec/sysUlFilesRecUploadW.jsp" flush="true" >
									<jsp:param name="filePath" value="arcfile/transfer"/>
									 <jsp:param name="fileNum" value="1"/>
								</jsp:include>
								 	<input id="tabNm"  name="tabNm"  type="hidden"  value="ARC_TRANSFER_MAIN">
							</div>
					</div>
					<!-- 签收单附件显示 -->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="ligergrid_file2" class="sq-grid"></div>
						</div>
					</div>
			</c:if>
		<!-- end 签收单及解押资料回执上传 签收单 003 -->	
					<!--选择的移交数据展示-->
					<div class="fieldBox col_100">
						<div style="width: 98%; margin-left: 1%;">
							<div id="ligergrid_transfer" class="sq-grid"></div>
						</div>
					</div>
					<!--邮寄 -->
					<jsp:include page="../arcMgr/arcPostList.jsp" flush="true" />
					<c:if test="${sign=='002' || sign=='001'}">	<!--只有省合同管理员可修改与添加邮寄信息-->
						<jsp:include page="../arcMgr/arcPostAdd.jsp" flush="true" />
					</c:if>	
					<c:if test="${sign=='006'}">
						<jsp:include page="../arcTransferMain/arcPostAdd.jsp" flush="true" />
					</c:if>
				</div>
				<div class="btnsBox" style="text-align:center">
					<c:if test="${sign=='002' || sign=='001' || sign=='006' || sign=='003'}">
						<c:if test="${operate != 'view'}">
						<span id="saveBtn" class="sq-button sq-button-round" onclick="save();">保存</span>
						<!-- <span id="closeBtn" class="sq-button sq-button-round" onclick="Remove_navTab();">关闭</span> -->
						</c:if>
					</c:if>	
				</div>
				 <div class="fieldBox col_100" style="display:none;">
					 <input  id="up_file_id" type="text" class="ui-textbox" value='${up_file_id }' >
					 <input  id="receipt_file_id" type="text" class="ui-textbox"  value="${receipt_file_id}"><!-- 签收单 -->
					 <input  id="t_is_need" type="text" class="ui-textbox" value='${avo.isNeed }'>
					  <!-- 上传文件使用：系统时间和当前登录人姓名 -->
                      <input name="sysDate" id="sysDate" type="text" class="ui-textbox" value="${sysDate }">
                      <input name="loginUsrNm" id="loginUsrNm" type="text" class="ui-textbox" value="${loginUsrNm }">
				</div>
			</form>
		</div>
	</div>
    
<script type="text/javascript">
	 	
	var grid;
	var mainId='${id}';	
	var up_file_id='${up_file_id}';
	var ssign='${sign}';
	var prefixUrl='${prefixUrl}';
	var payidstr="";
	$(function() {
		$("#ligerForm").ligerForm({
			validate: true
		});
		
		initGrid();//初始化移交选择数据列表
		isShowInfor('${avo.isNeed}');
		if(ssign=='006'){
			loadFilesLiger("jieya", 1, "${id}", "yes");
		}else if(ssign=='003'){
			loadFilesLiger("qian", 2, "${id}", "yes");
		}
		
    });
	var detailGrid;
	var detailGrid1;
	//初始化列表
	function initGrid(){
		//发起权证移交sign=006
		if(ssign!=null && ssign=='006'){
			$("#ligergrid_transfer").ligerGrid({
				url:'<%=path%>/archive/arcTransferMain/initTransferList.do',
				method:'get',
				parms:{'parentId':mainId,'sign':ssign},
				columns:[
					{ display: '承租人姓名', name: 'cstNm', minWidth: 100,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.cstNm+">"+rowdata.cstNm+"</span>";
						}
					},
					{ display: '合同号', name: 'contractNo', minWidth: 150,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.contractNo+">"+rowdata.contractNo+"</span>";
						}
					},
					{ display: '支付表号', name: 'paySchNo', minWidth: 170,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.paySchNo+">"+rowdata.paySchNo+"</span>";
						}
					},
					{ display: '结清时间', name: 'stlDt', minWidth: 50},
					{ display: '事业部', name: 'buOrgCdNm', minWidth: 60},
					{ display: '省公司', name: 'prOrgCdNm', minWidth: 90},
					{ display: '结清状态', name: 'prdStsCdNm', minWidth: 40,
						render:function (rowdata, rowindex, value){
							 var h="";
							 if(rowdata.prdStsCdNm=='正常'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='已拖回'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='拖回已转优车'){
								 h='';
							 }else{
								 h=rowdata.prdStsCdNm;
							 }
							 return h;
						 }
					},
					{ display: '交接单名称', name: 'arcReceiptName', minWidth: 40},
					{ display: '省公司档案编号', name: 'portfolioNumberProvince', minWidth: 30},
					{ display: '总部档案编号', name: 'portfolioNumber', minWidth: 30},
					{ display: '车架号', name: 'vin', minWidth: 30},
					{ display: '客户经理', name: 'cstMgrNm', minWidth: 30},
					{display:'其他资料', name: 'uploadFileList', minWidth: 120,
						 render: function (rowdata, rowindex, value) {
							 var h="";
							 h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="uploadDialog(';
							 h+="'"+rowdata.arcMgrMainId+"'";
				             h+=",'"+rowdata.paySchNo+"'";
				             h+=")\"><i class='sqBtnIco_9'></i>上传</a>";
				             if(rowdata.uploadFileList){
		 						 var listl=rowdata.uploadFileList;
		 						 for(var i=0;i<listl.length;i++){
		 							h+='<a   target="_blank" href="'+listl[i].filePath+'">'+listl[i].fileNm+'</a>';
		 							h+=' | <a  href="javascript:uploadFileDeleteById(';
					                h+="'"+listl[i].id+"'";
					                h+=",'"+listl[i].pkId+"'";
					                h+=')"><i class="sqBtnIco_7"></i>删除</a>';
		 						 }
		 					 }
							 return h; 
						 }
					},
				],
				pageSize:30,
				pageSizeOptions:[30,40,50], //可指定每页页面大小
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'100%',
				heightDiff:-2,
				isScroll: true,
				root: 'rows',
				hideLoadButton:false,
				frozen: false,
				//checkbox:true,//列表是否有选择框
				onAfterShowData: function(){
					<c:if test="${sign == '002' || sign=='001' }">
					this.extendDetailAll();
					</c:if>
					<c:if test="${sign == '006' && avo.isNeed==1}">
						this.extendDetail(0);
					</c:if>
					
					//this.extendDetail(1);
				 },
	            /* onBeforeShowData: function ()
	            {
	                var grid = this;
	                grid.collapsedRows = [];
	            }, */
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				rownumbers:true,//列表是否有行号
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
					
				},
				 detail: {
		             height: 'auto',
		             onShowDetail: initWarrantGrid
		         }
			});
		}else {
			$("#ligergrid_transfer").ligerGrid({
				url:'<%=path%>/archive/arcTransferMain/initTransferList.do',
				method:'get',
				parms:{'parentId':mainId},
				columns:[
					{ display: '承租人姓名', name: 'cstNm', minWidth: 100,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.cstNm+">"+rowdata.cstNm+"</span>";
						}
					},
					{ display: '合同号', name: 'contractNo', minWidth: 150,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.contractNo+">"+rowdata.contractNo+"</span>";
						}
					},
					{ display: '支付表号', name: 'paySchNo', minWidth: 170,
						render:function (rowdata, rowindex, value){
							return "<span title="+rowdata.paySchNo+">"+rowdata.paySchNo+"</span>";
						}
					},
					{ display: '结清时间', name: 'stlDt', minWidth: 50},
					{ display: '事业部', name: 'buOrgCdNm', minWidth: 60},
					{ display: '省公司', name: 'prOrgCdNm', minWidth: 90},
					{ display: '结清状态', name: 'prdStsCdNm', minWidth: 40,
						render:function (rowdata, rowindex, value){
							 var h="";
							 if(rowdata.prdStsCdNm=='正常'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='已拖回'){
								 h='';
							 }else if(rowdata.prdStsCdNm=='拖回已转优车'){
								 h='';
							 }else{
								 h=rowdata.prdStsCdNm;
							 }
							 return h;
						 }
					},
					{ display: '交接单名称', name: 'arcReceiptName', minWidth: 40},
					{ display: '省公司档案编号', name: 'portfolioNumberProvince', minWidth: 30},
					{ display: '总部档案编号', name: 'portfolioNumber', minWidth: 30},
					{ display: '车架号', name: 'vin', minWidth: 30},
					{ display: '客户经理', name: 'cstMgrNm', minWidth: 30},
				],
				pageSize:30,
				pageSizeOptions:[30,40,50], //可指定每页页面大小
				record:'total',
				hideLoadButton:false,
				width:'100%',
				height:'100%',
				heightDiff:-2,
				isScroll: true,
				root: 'rows',
				hideLoadButton:false,
				frozen: false,
				//checkbox:true,//列表是否有选择框
				onAfterShowData: function(){
					<c:if test="${sign == '002' || sign=='001' || sign=='003'}">
					this.extendDetailAll();
					</c:if>
					<c:if test="${sign == '006' && avo.isNeed==1}">
						this.extendDetail(0);
					</c:if>
					//this.extendDetail(1);
				 },
	            /* onBeforeShowData: function ()
	            {
	                var grid = this;
	                grid.collapsedRows = [];
	            }, */
				selectRowButtonOnly:true,//复选框模式时，是否只允许点击复选框才能选择行
				rownumbers:true,//列表是否有行号
				//选择行事件
				onSelectRow: function(rowdata, rowid, rowobj){
					
				},
				//取消选择行事件
				onUnSelectRow : function(rowdata, rowid, rowobj){
					
				},
				 detail: {
		             height: 'auto',
		             onShowDetail: initWarrantGrid
		         }
			});
		}
		
		grid = liger.get("ligergrid_transfer");
		grid.setHeight(100);
	}
	//初始化权证资料列表       归档地点 1总部 2省公司
	function initWarrantGrid(row, detailPanel, callback) {
	 var gridBox = document.createElement('div');
	    $(gridBox).css('margin', 10);
	    $(detailPanel).css({
	        'padding': 10,
	        'box-sizing': 'border-box'
	    }).append(gridBox);
	      detailGrid = $(gridBox).ligerGrid({
	    	url:'<%=path%>/archive/arcTransferMain/initGridList.do',
	    	parms:{contractNo: row.contractNo, payListCode: row.paySchNo, arcLevel: "2",fileFlag:"3",'ssign':'${sign}'},
	        method: 'get',
	        columns:[
	     			{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
	     			{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
	     			{ display: '资料类型', name: 'dossierTempNm', minWidth: 160, align: 'center', enabledSort: true},
	     			{ display: '存档份数', name: 'dossierCountT', minWidth: 160, align: 'center', enabledSort: true},
	     			gettransferCount(),
	     			
	     			
	     		],
	        root: 'rows',
	        hideLoadButton: true,
	        width: '100%',
	        height: 'auto',
	        heightDiff:-2,
	        isScroll: false,
	        rownumbers: true,  //显示序号
	        checkbox: false,
	        allowUnSelectRow: true,
	        alternatingRow: true,
	        onAfterShowData: callback,
	        enabledEdit: true,
	        frozen: false,
	        usePager: false
	    });
	  //ssign 003
	  if(ssign=='003'){//签收单及解押资料回执上传
		  var gridBox1 = document.createElement('div');
		    $(gridBox1).css('margin', 10);
		    gridBox1.setAttribute("jieClass", "jieClass");
		    $(detailPanel).css({
		        'padding': 10,
		        'box-sizing': 'border-box'
		    }).append(gridBox1);
		      detailGrid1 = $(gridBox1).ligerGrid({
		    	url:'<%=path%>/archive/arcTransferMain/initJGridList.do',
		    	parms:{'transferMainId': row.id,'ssign':'${sign}'},
		        method: 'get',
		        columns:[
		     			{ display: '权证类别', name: 'fileFlagNm', minWidth: 150, align: 'center', enabledSort: true},
		     			{ display: '权证名称', name: 'fileName', minWidth: 180, align: 'center', enabledSort: true},
		     			{ display: '资料类型', name: 'dossierTempNm', minWidth: 100, align: 'center', enabledSort: true},
		     			{ display: '要求份数', name: 'dossierCount', minWidth: 100, align: 'center', enabledSort: true},
		     			{ display: '是否必须', name: 'ischoiceNm', minWidth: 100, align: 'center', enabledSort: true},
		     			{ display: '归档份数', name: 'transferNumber', width: 100, type: 'int',editor: {type: 'int'},
		     				render:function (rowdata, rowindex, value){
		     					var  h="";
		     					if(rowdata.transferNumber>0){
		     						h=rowdata.transferNumber;
		     					}else{
		     						h=rowdata.dossierCount;
		     					}
		     					return h;
		     				}
		     				
		     				
		     			},
		     			{ display: '扫描件', name: 'scanAttcheList', minWidth: 200, align: 'center', enabledSort: true,
		     				 render:function (rowdata, rowindex, value){
		     					var  h="";
		     					 h += '<a class="sq-button-hasicon" style="cursor:pointer;" onclick="upload(' + rowdata.id + ');"><i class="sqBtnIco_9"></i>上传</a>'; 
		     					 h+="||";
		     					 h+='<span  class="upfiles" id="'+rowdata.id+'" fflag="1"  pkId="'+rowdata.id+'"  style="text-align:left"></span>';
     					    	if(rowdata.scanAttcheList){
		     						 var listl=rowdata.scanAttcheList;
		     						 for(var i=0;i<listl.length;i++){
		     							h+='<a   target="_blank" href="'+listl[i].filePath+'">'+listl[i].fileNm+'</a>';
		     							h+=' | <a  href="javascript:uploadFileDeleteById(';
		    			                h+="'"+listl[i].id+"'";
		    			                h+=",'"+listl[i].pkId+"'";
		    			                h+=')"><i class="sqBtnIco_7"></i>删除</a>';
		     						 }
		     					 }	
		     					 return h;
		     				 }
		     			}
		     		],
		        root: 'rows',
		        hideLoadButton: true,
		        width: '100%',
		        height: 'auto',
		        heightDiff:-2,
		        isScroll: false,
		        rownumbers: true,  //显示序号
		        checkbox: false,
		        allowUnSelectRow: true,
		        alternatingRow: true,
		        onAfterShowData: callback,
		        enabledEdit: true,
		        frozen: false,
		        usePager: false
		    });   
	  }//签收单及解押资料回执上传
	}
	//"实际移交份数"列是否可编辑
    function gettransferCount(){
		var data = {display: '实际移交份数', name: 'transferCount', width: 150, align: 'center', enabledSort: true,
				render:function (rowdata, rowindex, value){
					 var h="";
					 if(rowdata.transferCount>0){
						 h = rowdata.transferCount;
					 }else if(rowdata.dossierCountT>0){
						 h = rowdata.dossierCountT;
					 }else {
						 h="0";
					 }
					 return h;
			 	}};
		<c:if test="${sign == '002' || sign=='001'}">
			data = {display: '实际移交份数', name: 'transferCount', width: 150, type: 'int', 
						editor: {
							type: 'int'
						},
			 	render:function (rowdata, rowindex, value){
					 var h="";
					 if(rowdata.transferCount>0){
						 h = rowdata.transferCount;
					 }else if(rowdata.dossierCountT>0) {
						 h = rowdata.dossierCountT;
					 }else {
						 h="0";
					 }
					 return h;
			 	}
			};
		</c:if>
		<c:if test="${sign == '006'}">
		data = {display: '已移交份数', name: 'transferCount', width: 150, align: 'center', enabledSort: true,
				render: function (rowdata, rowindex, value){
					return '<span>0</span>';
				   }
				};
		</c:if>
		
		return data;
	}
	//保存
	function save(){
			
		var ligerForm = liger.get("ligerForm");
		if (!ligerForm.valid()) {
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
			return false; 
		}
		var sign='${sign}';// 只有省合同管理员或总部权证可以修改邮寄信息
		var listGrid=$(".l-grid-detailpanel-inner");
		var _dtlArray = [];//权证资料
		for(var i=0;i<listGrid.length;i++){//遍历权证资料
			var tempObj=listGrid[i];
			var detailGridID=$(tempObj).find('[ligeruiid]').attr('ligeruiid');
			var dtlGrid = liger.get(detailGridID);
			var _dtls=dtlGrid.getData();
	        for (var index in _dtls) {
	           
	        	_dtlArray.push({'id':_dtls[index].id,'transferCount':_dtls[index].transferCount,'dossierCountT':_dtls[index].dossierCountT});
	            
	        }
		}//
		//遍历结清资料l-panel
		//upfiles 是否需要解押材料来判断是否必填
		var _jieArray = [];//结清资料
		var isNeed=$('#t_is_need').val();
		if(sign!=null && sign=='003'){
			var nodeList= document.getElementsByClassName("l-panel");
			for(var k=0;k<nodeList.length;k++){
				var nobj=nodeList[k];
				var jc=$(nobj).attr('jieClass');
				if(jc!=null && jc=='jieClass'){
					var jid=$(nobj).attr('ligeruiid');
					var jiGrid = liger.get(jid);
					var _jData=jiGrid.getData();
					for (var inde in _jData) {//放入归档份数
					
			            _jieArray.push({'id':_jData[inde].id,'transferNumber':_jData[inde].transferNumber,'dossierCount':_jData[inde].dossierCount});
				    }
				}
			}
			
			
			//签收单及解押资料回执上传增加签收单必传验证
			var upFileId=$('#receipt_file_id').val();
			if('undefined'==upFileId || ""==upFileId || null==upFileId){
				$.ligerDialog.SQalert({content: '请上传签收单',SQ_type: "success"});
                return;
			}
			//验证扫描件是否都上传了
			if(null!=isNeed && isNeed=='1'){
				var re=	jyScancheck('${id}');//// Code: 0 成功  2 失败
				console.log("re"+re);
				if(re.data=='2'){
					$.ligerDialog.SQalert({content: re.info,SQ_type: "warning"});
					return ;
				 } 
					
			}
		}//end 结清资料
		//发起权证移交节点  校验解押材料申请表
		if(sign!=null && sign=='006'){
			if(null!=isNeed && isNeed=='1'){
				var jiya= $('#up_file_id').val();
				if(jiya==''||jiya==null || jiya=='undefined'){
					 $.ligerDialog.SQalert({content: "请上传解押材料申请表!",SQ_type: "warning"});
					return ;
				}
			}	
		}//校验解押材料申请表
			
		//校验邮寄信息
		if(sign!=null && (sign=='002' ||sign=='001')){
			if(!checkPost()){
				return ;
			}
		}
		//校验sign=='006' 快递公司 快递单号不必填
		if(sign!=null && sign=='006'){
			if(!checkPostN()){
				return ;
			}
		}//end by sign=='006'
	
		var data = ligerForm.getData();//主表数据
		console.log(JSON.stringify(_jieArray));
		data['griddata1']=JSON.stringify(_dtlArray);//权证资料
		data['griddata2']=JSON.stringify(_jieArray);//结清资料
		var wait_dialog = null;
		//提示确认移交份数
		if(sign!=null && (sign=='002' ||sign=='001')){
			$.ligerDialog.confirm('确认移交份数吗?', function (flag) {
				if(flag == false)return;
				$.ajax({
					type: 'post',
					dataType: 'json',
					data: data,
					url: '<%=path%>/archive/arcTransferMain/modifyFlowN.do?sign=${sign}&id=${id}&paySchNo=${paySchNo}',
					beforeSend: function(){
						wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
					},success:function(msg){
						wait_dialog.close();
						if(msg.success == 1){
							$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
								//if(id == "") {
									//Remove_navTab();//新增，关闭当前页面
								//}
							window.location.reload();
						}else{
							$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
						}
					},error:function (XMLHttpRequest, textStatus, errorThrown) { 
						wait_dialog.close();
						$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
					} 
				});
			})
		}else{
			$.ajax({
				type: 'post',
				dataType: 'json',
				data: data,
				url: '<%=path%>/archive/arcTransferMain/modifyFlowN.do?sign=${sign}&id=${id}&paySchNo=${paySchNo}',
				beforeSend: function(){
					wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
				},success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
							//if(id == "") {
								//Remove_navTab();//新增，关闭当前页面
							//}
						window.location.reload();
					}else{
						$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
					}
				},error:function (XMLHttpRequest, textStatus, errorThrown) { 
					wait_dialog.close();
					$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
				} 
			});
		}
		
		
	}
	//是否需要解押材料为是，校验是否都上传了扫描件
	function   jyScancheck(mainId){
		// Code: 0 失败  1 成功
		var re=0;
	   var data;
		$.ajax({
			type: 'post',
			dataType: 'json',
			async:false,
			data: {'mainId':mainId},
			url: '<%=path%>/archive/arcTransferMain/checkScanFile.do?',
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting"});
			},success:function(msg){
				wait_dialog.close();
				data=msg;
				/* if(msg.data == 1){
					re=1;
				}else{
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				} */
			},error:function (XMLHttpRequest, textStatus, errorThrown) { 
				wait_dialog.close();
				$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
			} 
		});
		return data;
	} 
	//查找人
	function searchBtn(){
		
		var wait_dialog = null;
		
		$.ajax({
			type: 'post',
			dataType: 'json',
			
			url: '<%=path%>/archive/arcMgrMain/searchBtn.do?idCardNM='+$("#idCardNM").val(),
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$("#idCard").val(msg.data.usrNm);
					$("#recipient").val(msg.data.refRlNm);
					$("#mobile").val(msg.data.mp);
				}else{
					$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			},error:function (XMLHttpRequest, textStatus, errorThrown) { 
				wait_dialog.close();
				$.ligerDialog.SQalert({content: "网络错误，请稍后重试",SQ_type: "error"});
			} 
		});
	}
	//是否显示解押材料 解押材料申请表
	function isShowInfor(val){
		if(val=='1'){
			$('#jieYaInfo').show();
		}else if(val=='0'){
			$('#jieYaInfo').hide();
		}
	}
	//上传回调
	function  uploadCallback(fileData){
		var sign='${sign}';//(cfgDtlCd=30解押材料 sign=006)  (cfgDtlCd=80签收单 sign=003)  
		var cfgDtlCd='30';
		if(sign!=null && sign=='003'){
			cfgDtlCd='80';
		}
		var up_file_id= $('#up_file_id').val();//解押材料
		var receipt_file_id=$('#receipt_file_id').val();//签收单
		var params = {};
			  params.fileNm=fileData[0].fileNm;
			  params.filePath=fileData[0].filePath;
			  params.tabNm = "ARC_TRANSFER_MAIN";
			  params.cfgCd ="ARC001";
			  params.cfgDtlCd =cfgDtlCd;
			  params.pkId ="${id}";
			  params.up_file_id=up_file_id;
			  params.receipt_file_id=receipt_file_id;
	    var url = '<%=path%>/archive/arcTransferMain/saveUploadRecord.do';
	    $.ajax({
			type: 'post',
			dataType:'json',
			data:params,
			url: url,
			success:function(msg){
				 if(msg.success == 1){
					var dat = msg.data;
				    $('#up_file_id').val(dat.id);
				    if(sign!=null && sign=='003'){
				    	$('#receipt_file_id').val(dat.id);
					}
				    if(sign!=null && sign=='006'){
				    	 showFiles(fileData,1,dat.id);//解押申请表
					}else{
						 showFiles(fileData,2,dat.id);//签收单
					}
				 }else{
					 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				 }
			}
		});
	   
	}//
	//显示已上传但是未保存的文件列表
	function showFiles(data, index,id){
		var sysDate = $("#sysDate").val();
		var loginUsrNm = $("#loginUsrNm").val();
		var f_Grid = liger.get("ligergrid_file"+index);
		var trdata = f_Grid.getRow("0");
		//删除之前上传的文件
		if(trdata!=null){
			f_Grid.deleteRow(trdata);
		} 
		//deleteRow
		var uploadJOSN = data;
		for (var i=0; i< uploadJOSN.length; i++){ 
    		//添加行-追加行
    		f_Grid.addRow({fileNm: uploadJOSN[i].fileNm, crtUsrRlNm: loginUsrNm, crtTm: sysDate, doSthFlag: "1", ligerIndex: index, id: id,filePath:prefixUrl+uploadJOSN[i].filePath});
		}
	}
	//下载附件
	function downFile(_url,_name){
		if(SQ.regs.img.test(_name)){
			SQ.imgPreview(_url, true);
		}else{
			window.open(_url);
		}
	}
	//上传
	function upload(id){
		//设置一下 
		/* $(".upfiles").each(function(){
			 $(this).attr("pkId",id);
			 $(this).attr("id",id);
			 //$(this).attr("fff",rowdata.);
	     }); */
		$.ligerDialog.SQopen({
            width: 820,
            height:550,
            title : '上传文件',
            url:'<%=path%>/archive/arcApplyMain/toUpload.do?flag=2&id='+id,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
            	text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onOk = function () {}
                    if (Dialog.onOk) {
                    	Dialog.onOk();
                    	//window.parent.detailGrid1.reload();
                    }
                    
                }
            }, {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
	}
	//签收单及解押材料下载批量下载
    function batchDownload() {
    	
		var actoinURL = '<%=path%>/archive/arcTransferMain/batchDownload.do';
    	var form = $("<form>");
        $('body').append(form);
        form.attr('style','display:none');
        form.attr('target','');
        form.attr('method','post');
        form.attr('action',actoinURL);
      
        var input = $('<input>');
        input.attr('type','hidden');
        input.attr('name','applyId');
        input.attr('value','${id}');
        form.append(input);
       
        form.submit();
    }
    function uploadFileDeleteById(id,pkId){
    	if(!id){
    		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
    		return;
    	}
    	$.ligerDialog.confirm('确定删除吗?', function (flag) {
    		if(flag == false)return;
    		var wait_dialog;
    		$.ajax({
    			type: 'post',
    			dataType:'json',
    			data:{id:id},
    			url: '<%=path%>/system/sysulfilesrec/removeById.do',
    			beforeSend: function(){
    		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
    		     },
    			success:function(msg){
    				wait_dialog.close();
    				 if(msg.success == 1){
    					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
    					 grid.reload();
    				 }else{
    					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    				 }
    			}
    		});
    	});
    }
    function uploadFileDeleteRow(id,dataId,pkId){
    	if(!id){
    		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
    		return;
    	}
    
    	$.ligerDialog.confirm('确定删除吗?', function (flag) {
    		if(flag == false)return;
    		var wait_dialog;
    		$.ajax({
    			type: 'post',
    			dataType:'json',
    			data:{id:id},
    			url: '<%=path%>/system/sysulfilesrec/removeById.do',
    			beforeSend: function(){
    		          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
    		     },
    			success:function(msg){
    				wait_dialog.close();
    				 if(msg.success == 1){
    					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
    					  grid.reload();
    					  /* if(){
    						  
    					  } */
    					  
    				 }else{
    					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    				 }
    			}
    		});
    	});
    }
  //上传其他资料
function uploadDialog(id,paySchNo){
    	$.ligerDialog.SQopen({
            width: 300,
            height:200,
            title : '上传其他资料',
            url:'<%=path%>/archive/arcTransferMain/toUpload.do?id='+id+'&paySchNo='+paySchNo,
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [ {
                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
            ]
        });
    }
	</script>
<!-- 显示上传文件列表 -->
<script type="text/javascript">
var fileGrid = null;

//加载所有文件列表：标识、序号、主键、是否可删除
function loadFilesLiger(flag, index, pkId, isDel){
	var param = null;
	var ligerNm = "ligergrid_file"+index;
	var _url = '<%=path%>/rfbuss/fncPrjContDetail/initFilesList.do';
	if(flag == "jieya"){//解押材料申请表
		param = {
				pkId: pkId,//ID
				tabNm: "ARC_TRANSFER_MAIN",
				cfgDtlCd:"30",
				cfgCd:"ARC001"
		};
	}else if(flag == "qian"){//移交申请-签收单
		param = {
				pkId: pkId,//ID
				tabNm: "ARC_TRANSFER_MAIN",
				cfgDtlCd:"80",
				cfgCd:"ARC001"
		};
	}
	
    load_FileList(flag, ligerNm, _url, param, index, isDel);
}

//加载
function load_FileList(flag, ligerNm, _url, param, index, isDel){
	$("#"+ligerNm).ligerGrid({
			usePager: false,
			url: _url,
			method : 'get',
			parms:param,
			columns:getColumns(flag, index, isDel),//动态获取列
			pageSize:10,
			root:'rows',
			record:'total',
			hideLoadButton : true,
			width: '100%',
			rownumbers:true,
			checkbox:true,//列表是否有选择框
			onAfterShowData: function () {
				$( ".gridTip").grid_ligerTip();
				SetIframe_height ();
			}
	});
	fileGrid = liger.get(ligerNm);
	fileGrid.options.isSingleCheck = false;//列表是否为单选
}

//获取列表列
function getColumns(flag, index, isDel){
	var col_data = [
			{ display: '名称', name: 'fileNm', minwidth: 200, enabledSort:true },
			{ display: '提交人员', name: 'crtUsrRlNm', width: 200, enabledSort:true },
			{ display: '提交时间', name: 'crtTm', width: 200, render:renderDate2, enabledSort:true },
			getGridOperColumnWarrant(flag, index, isDel)//操作列
		];
	return col_data;
}

//文件从数据库删除 操作列
function getGridOperColumnWarrant(flag, index, isDel){
	var data = {
		display: '操作',
		isSort: false,
		minWidth: 100,
		render: function (rowdata, rowindex, value){
			var h="";
			h+='<a class="sq-button-hasicon" href="javascript:uploadFileByUrl(';
            h+="'"+rowdata.filePath+"'";
            h+=",'"+rowdata.fileNm+"'";
            h+=')"><i class="sqBtnIco_8"></i>下载</a>';
			//是否有删除操作
			if(null != flag && "hkb" != flag && isDel == "yes"){
				h+='<a class="sq-button-hasicon" href="javascript:uploadFileDeleteRow1(';
				h+="'"+rowdata.id+"'";
				h+=",'"+index+"'";
				h+=')"><i class="sqBtnIco_7"></i>删除</a>';
			}
			return h;
		}
	};
	return data;
}
//下载文件方法
function uploadFileByUrl(_url,_name){
	if(SQ.regs.img.test(_name)){
		SQ.imgPreview(_url, true);
	}else{
		window.open(_url);
	}
}

//删除调用方法
function uploadFileDeleteRow1(id, index){
	if(!id){
		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW , SQ_type: "warning" });
		return;
	}
	$.ligerDialog.confirm('确定删除吗?', function (flag) {
		if(flag == false)return;
		var wait_dialog = null;
		$.ajax({
			type: 'post',
			dataType:'json',
			data:{id:id},
			url: '<%=path%>/system/sysulfilesrec/removeById.do',
			beforeSend: function(){
				wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
					liger.get("ligergrid_file"+index).reload();//刷新
					if(index=='1'){
						$('#up_file_id').val("");//清空上传文件
					}
					if(index=='2'){
						$('#receipt_file_id').val("");//清空上传文件
					}
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			}
		});
	});
}



//格式化时间2：YYYY-MM-DD
function renderDate2(rowdata, index, value){
	var dateStr = "";
	if(null != value){
		var date = new Date(value);
		dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
	}
	return dateStr;
}
//校验邮寄信息 
function checkPostN(){
	if($.trim($("#idCard").val()) == ""){
		$.ligerDialog.SQalert({content: "输入工号，点击'查找收件人'，查询出收件人（工号）和收件人（姓名）",SQ_type: "warning",SQ_showButtons: true});
		return false;
	} 
   if($.trim($("#mobile").val()) == ""){
		$.ligerDialog.SQalert({content: "请填写联系电话",SQ_type: "warning",SQ_showButtons: true});
		return  false;
	} 
   if($.trim($("#sendType").val()) == ""){
		$.ligerDialog.SQalert({content: "请选择接收方式",SQ_type: "warning",SQ_showButtons: true});
		return  false;
	}
  
   if($.trim($("#sendType").val()) == 0){
	   /* if($.trim($("#sendCompany").val()) == ""){
			$.ligerDialog.SQalert({content: "请选择快递公司",SQ_type: "warning",SQ_showButtons: true});
			return  false;
		} 
	   if($.trim($("#sendNum").val()) == ""){
			$.ligerDialog.SQalert({content: "请输入快递单号",SQ_type: "warning",SQ_showButtons: true});
			return  false;
		} */
	   if($.trim($("#sendAddr").val()) == ""){
			$.ligerDialog.SQalert({content: "请输入邮寄地址",SQ_type: "warning",SQ_showButtons: true});
			return  false;
		}
	}
   return true;

}
</script>
</body>
</html>
